﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Icst.Leaflike.Data;
using System.Threading;
using System.IO;

namespace Icst.Leaflike
{
    public static class AppConfig
    {
        public static string ConnectionString { get { return ConfigurationManager.ConnectionStrings["default"].ConnectionString; } }

        public static float searchthrehold { get { return float.Parse(SysSetting.Instance["searchthrehold"]); } }
        public static string forum_home { get { return SysSetting.Instance["forum_home"]; } }
        public static string forum_forum { get { return SysSetting.Instance["forum_forum"]; } }
        public static string forum_admin { get { return SysSetting.Instance["forum_admin"]; } }
        public static string forum_profile { get { return SysSetting.Instance["forum_profile"]; } }
        public static string forum_register { get { return SysSetting.Instance["forum_register"]; } }
        public static string DNTWebServer { get { return SysSetting.Instance["DNTWebServer"]; } }
        public static string DNTAPIKey { get { return SysSetting.Instance["DNTAPIKey"]; } }
        public static string DNTSecert { get { return SysSetting.Instance["DNTSecert"]; } }

        public static int forbiddenthrehold { get { return int.Parse(ConfigurationManager.AppSettings["forbiddenthrehold"]); } }
        public static int onlineuserthrehold { get { return int.Parse(ConfigurationManager.AppSettings["onlineuserthrehold"]); } }
        public static string cookiedomain { get { return ConfigurationManager.AppSettings["cookiedomain"]; } }
        public static int sessiontimeout { get { return int.Parse(ConfigurationManager.AppSettings["sessiontimeout"]); } }

        /// <summary>
        /// SAFG configuration
        /// </summary>
        public static string SAFGcache { get { return Read("SAFGcache",Path.Combine(Thread.GetDomain().BaseDirectory, "SAFG.cache")); } }
        public static string SAFGclist { get { return Read("SAFGclist", Path.Combine(Thread.GetDomain().BaseDirectory, "SAFG.clist")); } }
        public static string SAFGIDtag { get { return Read("SAFGIDtag", Path.Combine(Thread.GetDomain().BaseDirectory, "SAFG.IDtag")); } }
        public static string SAFGsai { get { return Read("SAFGsai",Path.Combine(Thread.GetDomain().BaseDirectory, "SAFG.sai")); } }

        //public static string ContourTmpPath(Page page)
        //{
        //    string path = SysSetting.Instance["ContourTmpPath"];
        //    if (string.IsNullOrEmpty(path))
        //        path = page.Server.MapPath("~/contours");
        //    return path;
        //}
        public static string ContourUrl(string id) 
        {
            string contours = SysSetting.Instance["contours"];
            return contours + "?id=" + id; 
        }
        public static string Read(string key, string defaultValue)
        {
            string value = SysSetting.Instance[key];
            return string.IsNullOrEmpty(value) ? defaultValue : value;
        }
    }
}
